<%@page import="java.util.ArrayList"%>
<%@page import="model.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../css/history.css"/>
<title>Insert title here</title>
<%
	String userId = (String)session.getAttribute("userId");
	if(userId == null) {
		response.sendRedirect("index.jsp");
	}
	
	ArrayList<UserProjectList> list = (ArrayList<UserProjectList>)request.getAttribute("projectList");
	
%>
</head>
<script src="../js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
	var list;
	$(document).ready( function(){
		$("#projectSelect").change(function(){
			var k = $("#projectSelect").val().split("?");
			var oldProjectId = k[0];
			if(oldProjectId == "nonselect")
				return;
			var completecnt = k[1];
			var isOldProject = k[2]; 
			$.ajax({
				method : "GET",
				url : "../ajaxQuery.do",
				data : "oldProjectId="+ oldProjectId + "&completecnt=" + completecnt + "&isOldProject=" + isOldProject,
				success : responseProjectData
			});
		})
	});
	
	function responseProjectData(data) {
		list = data;
		var i = 0;
		$("#programTable tbody").remove();
		$tbody = $("<tbody></tbody>");
		for(i = 0 ; i < data.length ; i++) {
		$tr = $("<tr></tr>");
		$cnt = $("<th></th>").text(i+1);
		$day = $("<th></th>").text(data[i].day);
		$weight = $("<th></th>").text(data[i].todayweight);
		$food1name = $("<th></th>").text(data[i].foodname1);
		$food1tf = $("<th></th>").text(data[i].isfood1);
		$food2name = $("<th></th>").text(data[i].foodname2);
		$food2tf = $("<th></th>").text(data[i].isfood2);
		$food3name = $("<th></th>").text(data[i].foodname3);
		$food3tf = $("<th></th>").text(data[i].isfood3);
		$exer1name = $("<th></th>").text(data[i].exername1);
		$exer1tf = $("<th></th>").text(data[i].isexer1);
		$exer2name = $("<th></th>").text(data[i].exername2);
		$exer2tf = $("<th></th>").text(data[i].isexer2);
		$exer3name = $("<th></th>").text(data[i].exername3);
		$exer3tf = $("<th></th>").text(data[i].isexer3);
		$comment = $("<th></th>").text(data[i].comment);
		$tr.append($cnt)
		.append($day)
		.append($weight)
		.append($food1name)
		.append($food1tf)
		.append($food2name)
		.append($food2tf)
		.append($food3name)
		.append($food3tf)
		.append($exer1name)
		.append($exer1tf)
		.append($exer2name)
		.append($exer2tf)
		.append($exer3name)
		.append($exer3tf)
		.append($comment);
		$tbody.append($tr);
		}
		$("#programTable").append($tbody);
	};

</script>
<body>
<div id="set">
	<jsp:include page="logonmenu.jsp"></jsp:include>
	<div id="line">
	<div id="history">
	<img src="../history.png"height=100>
	</div>
	<div id="program">
	<select id="projectSelect">
		<option value="nonselect">&lt;프로그램 목록&gt;</option>
		<%
			for(int i = 0 ; i < list.size() ; i++) {
				if(list.get(i).isEnd() == false) {
					out.print("<option value='" + list.get(i).getProgramId() +"?0?false'>[진행중인 프로그램] "+ list.get(i).getProgramName() +"</option>");
				} else {
					out.print("<option value='" + list.get(i).getProgramId() +"?"+list.get(i).getCompleteCnt()+"?true'>[완료된 프로그램"+list.get(i).getCompleteCnt()+" ] "+ list.get(i).getProgramName() +"</option>");
				}
			}
		%>
	</select>
	</div>
	<br>
	<div id="programTableDiv">
		<table id="programTable" border="1">
			<thead>
				<tr>
					<th>No</th>
					<th>day</th>
					<th>체중 변화</th>
					<th colspan="2">아침</th>
					<th colspan="2">점심</th>
					<th colspan="2">저녁</th>
					<th colspan="2">운동1</th>
					<th colspan="2">운동2</th>
					<th colspan="2">운동3</th>
					<th colspan="2">코멘트</th>
				</tr>
			</thead>
		</table>
	</div>
	<div id="logo">
	<img src="../gogologo.png" width=200, height=200>
	</div>
	</div>
	</div>
</body>
</html>
